<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>addJavascript - Generator - Prails API Documentation</title>
    </head>
    <body>
        <h3 class="P4"><a name="_addJavascript_"><span/></a>addJavascript </h3><h4 class="Heading_20_4"><a name="_Description_"><span/></a>Description:</h4>
        <p class="Standard">
            addJavaScript is used to register Javascript files for the current request. Javascript files registered in the Generator are minimized and packed together into one, static file, stored in the Javascript Cache. For every used combination of Javascript files registered, a different Javascript Cache file is created. Once this cache entry exists, no more repacking and re-minimizing is needed for this combination of Javascript files in all subsequent requests. If a Javascript file changed since the cache file has been generated, the old cache entry is removed and will be newly generated.
        </p>
        <p class="Standard">
        </p>
        <h4 class="Heading_20_4"><a name="_Syntax_"><span/></a>Syntax:</h4>
        <p class="Text_20_body">
            <code>addJavaScript($str_file)</code>
        </p>
        <table border="0" cellspacing="0" cellpadding="0" class="Table1">
            <colgroup>
                <col width="85"/><col width="658"/>
            </colgroup>
            <tr>
                <td style="text-align:left;width:1.94cm; " class="Table1_A1">
                    <p class="Table_20_Contents">
                        $str_file
                    </p>
                </td>
                <td style="text-align:left;width:15.058cm; " class="Table1_B1">
                    <p class="Text_20_body">
                        path to the Javascript file to be registered. This file does not need to be on the same server
                    </p>
                </td>
            </tr>
        </table>
        <p class="Text_20_body">
        </p>
        <h4 class="Heading_20_4"><a name="_Example_"><span/></a>Example:</h4>
        <p class="Text_20_body">
            The following example will register the <code>prototype.js</code>
            for the current request, which can then be used within your HTML/Javascript code.
        </p>
        <pre>
            $obj_gen = Generator::getInstance();
            $obj_gen->addJavaScript("http://prototypejs.org/assets/2009/8/31/prototype.js");
        </pre>
        <p class="Text_20_body">
            then in your HTML code you could do:
        </p>
        <pre>
            <script type="text/javascript">
            document.observe("dom:loaded", function() {
               alert("Hello, World!");
            });
            </script>
        </pre>
        <p class="Text_20_body">
                    which would show an alert window, saying "Hello, World!" as soon as the DOM tree is fully loaded (<code>document.observe</code>
                    is registered within the <code>prototype.js </code>file).
		</p>
    </body>
</html>
